package com.pengpeng.rabbitmq.utils;

import com.pengpeng.rabbitmq.exception.RabbitMQExceptionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author 彭鹏
 * @date 2021/10/19.
 */
public class ClassUtils {
    /**
     * 获取类中所有的field
     *
     * @param clazz
     * @return
     */
    public static List<Field> getAllField(Class clazz) {
        if (clazz == null) {
            RabbitMQExceptionUtils.throwRabbitMQException();
        }
        Field[] fields = FieldUtils.getAllFields(clazz);
        if (fields != null && fields.length > 0) {
            return Arrays.asList(fields);
        }
        return new ArrayList<>();
    }
}

